package com.example.servicetest;

import android.app.Notification;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Intent;
import android.os.Binder;
import android.os.IBinder;
import android.util.Log;

public class MyService extends Service{
		private DownloadBinder mBinder = new DownloadBinder();
		class DownloadBinder extends Binder{
			public void startDownload(){
				Log.d("MyService", "startDownload executed");
			}
			public int getProgress(){
				Log.d("MyService", "getProgress executed");
				return 0;
				
			}
		}
	@Override
	public IBinder onBind(Intent intent) {
		// TODO Auto-generated method stub
		return mBinder;
	}
	@Override
	public void onCreate() {
		// TODO Auto-generated method stub
		super.onCreate();
		
		Notification notification = new Notification(R.drawable.ic_launcher,"Notification comes",System.currentTimeMillis());
		Intent notificationiIntent = new Intent(this,MainActivity.class);
		PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationiIntent, 0);
		notification.setLatestEventInfo(this, "this is a title", "this is content", pendingIntent);
		startForeground(1, notification);
		Log.d("MyService", "onCreate executed");
	}
	public int onStartCommand(Intent intent,int flags,int startId){
		new Thread(new Runnable() {
			
			@Override
			public void run() {
				// TODO Auto-generated method stub
				stopSelf();
			}
		}).start();
		Log.d("MyService", "onStartCommand exectued");
		return super.onStartCommand(intent, flags, startId);
		
	}
	public void onDestory(){
		super.onDestroy();
		Log.d("MyService", "onDestroy executed");
	}
}


















